﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UFIDA.U9.AP.Enums;
using UFIDA.U9.CBO.FI.Enums;
using UFIDA.U9.CBO.SCM.Item;
using UFIDA.U9.PR.PurchaseRequest;
using UFIDA.U9.SM.SO;
using UFSoft.UBF.Business;
using UFSoft.UBF.Eventing;
using UFSoft.UBF.Util.DataAccess;

namespace UFIDA.U9.CusDev.QJKJPlugInBE
{
    class ProcessForPRtonull : IEventSubscriber
    {
        public void Notify(params object[] args)
        {

            if (args == null || args.Length == 0 || !(args[0] is UFSoft.UBF.Business.EntityEvent)) return;
            BusinessEntity.EntityKey key = ((UFSoft.UBF.Business.EntityEvent)args[0]).EntityKey;

            if (key == null || key.GetEntity() == null) return;
            //请购单
            UFIDA.U9.PR.PurchaseRequest.PR pr = key.GetEntity() as UFIDA.U9.PR.PurchaseRequest.PR;
            if (pr == null) return;

            #region 复制清空请购单:附件清单,单据状态,审批意见
            //清空审批意见
            if (pr.OriginalData.Status == PRStatusEnum.Approved && pr.Status == PRStatusEnum.OpenOpen)
            {
                if (pr.DescFlexField.PrivateDescSeg4 != "" || pr.DescFlexField.PrivateDescSeg4 != null)
                {
                    pr.DescFlexField.PrivateDescSeg4 = "";
                }
                //清空附件
                if (pr.DescFlexField.PrivateDescSeg5 != "" || pr.DescFlexField.PrivateDescSeg5 != null)
                {
                    pr.DescFlexField.PrivateDescSeg5 = "";
                }
                //清空oa标识
                if (pr.DescFlexField.PubDescSeg6 != "" || pr.DescFlexField.PubDescSeg6 != null)
                {
                    pr.DescFlexField.PubDescSeg6 = "";
                }
            }
            if (pr.Status == PRStatusEnum.OpenOpen)
            {
                if (pr.DescFlexField.PrivateDescSeg4 != "" || pr.DescFlexField.PrivateDescSeg4 != null)
                {
                    pr.DescFlexField.PrivateDescSeg4 = "";
                }
                //清空附件
                if (pr.DescFlexField.PrivateDescSeg5 != "" || pr.DescFlexField.PrivateDescSeg5 != null)
                {
                    pr.DescFlexField.PrivateDescSeg5 = "";
                }
                //清空oa标识
                if (pr.DescFlexField.PubDescSeg6 != "" || pr.DescFlexField.PubDescSeg6 != null)
                {
                    pr.DescFlexField.PubDescSeg6 = "";
                }
            }
            //单据标识
            if (pr.OriginalData.Status == PRStatusEnum.OpenOpen && pr.Status == PRStatusEnum.Approving)
            {
                int n = 1;
                if (pr.DescFlexField.PubDescSeg8 == "")
                {

                    pr.DescFlexField.PubDescSeg8 = n.ToString();
                }
                else
                {
                    pr.DescFlexField.PubDescSeg8 = (decimal.Parse(pr.DescFlexField.PubDescSeg8) + n).ToString();
                }
            }



            #endregion

        }

    }
}
